package cn.web03.websocket.dao;

import cn.web03.websocket.po.SocketMessageT;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;

import java.util.Date;
import java.util.List;
/**
 * @author 零三 2020.06
 * https://web03.cn
 */
public interface SocketMessageRepository extends JpaRepository<SocketMessageT,Long> {
    @Query(value = "SELECT * from t_socket_message where create_time < ?1 and receive_id = '0' ORDER BY create_time desc limit 15;", nativeQuery = true)
    List<SocketMessageT> getSocketMessageTByDate(Date date);
    @Query(value = "SELECT * from t_socket_message where ((launch_id = ?1 and receive_id = ?2) or (launch_id = ?2 and receive_id = ?1)) and create_time < ?3 ORDER BY create_time desc limit 15;", nativeQuery = true)
    List<SocketMessageT> getSocketMessageTByUser(String launchId,String receiveId,Date date);

    @Query(value = "select DISTINCT`launch_user` from t_socket_message where launch_id != '0' and receive_id = ?1 UNION ALL select DISTINCT`receive_user` from t_socket_message where launch_id = ?1 and receive_id != '0'", nativeQuery = true)
    List<String> getSocketUserRelevant(String launchId);
//    @Query(value = "select DISTINCT`receive_user` from t_socket_message where launch_id != 0 and receive_id = ?1", nativeQuery = true)
//    List<String> getSocketUserReceive(String receiveId);
}
